<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        fixed
        prop="sid"
        label="学号">
      </el-table-column>
      <el-table-column
        prop="college"
        label="学院">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="year"
        label="年级">
      </el-table-column>
      <el-table-column
        prop="major"
        label="专业">
      </el-table-column>
      <el-table-column
        prop="username"
        label="用户名">
      </el-table-column>

      <el-table-column
        fixed="right"
        label="操作"
        align="center">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="primary" icon="el-icon-edit-outline" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  created:function (){
    const _this = this;
    axios.get('http://localhost:8000/std/findStudent/'+ this.Global.sid +'').then(function (resp){
      _this.tableData = resp.data;
    })
  },
  watch:{
    $route(to,from){
      if(to.path=="/student"){
        const _this = this;
        axios.get('http://localhost:8000/std/findStudent/'+ this.Global.sid +'').then(function (resp){
          _this.tableData = resp.data;
        })
      }
    }
  },
  methods: {
    change(status,row){
      console.log(row);
      let i = status;
      if(i==1){
        i=0
      }else{
        i=1
      }
      let s;
      if(status==0){
        s = "是否禁用该用户？";
      }else{
        s = "是否启用该用户？";
      }
      let _this = this;
      this.$confirm(s, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios.post('http://localhost:8000/std/updateState',row).then(function (resp){
          if(resp.data == "success"){
            _this.$message("添加成功");
          }
        })
      }).catch(() => {
        row.state = i
      });
    },
    handleClick(row) {
      console.log(row);
      let arr = JSON.stringify(row);
      this.$router.push({
        path: '/updatePassword',
        query:{
          row: encodeURIComponent(arr)
        }
      })
    }
  },
  data() {
    return {
      tableData: null,
      value: true,
      sid: 5
    }
  },
}
</script>
